<script>
	const url = "http://127.0.0.1:1212";

	export default {
		onLaunch: function() {
			console.log('App Launch');
		},
		onShow: function() {
			console.log('App Show');
		},
		onHide: function() {
			console.log('App Hide');
		},
		globalData: {
			apiList: {
				login: url + '/api/login',
				adduser: url + '/api/adduser',
				usercenter: url + '/api/usercenter',
				useringoods: url + '/api/useringoods',
				goodslist: url + '/api/goodslist',
				delgoods: url + '/api/delgoods'
			}
		},
		methods: {
			apiPost(url, data, callback) {
				var that = this;
				var header = {
					'content-type': 'application/json;charset=UTF-8',
					"X-Requested-With": 'XMLHttpRequest'
				};
				if (uni.getStorageSync('access-token')) {
					header['access-token'] = uni.getStorageSync('access-token');
				}
				uni.request({
					url: url,
					data: data,
					method: 'POST',
					dataType: 'json',
					header: header,
					success: (res) => {
						console.log(res)
						if (res.data.code == 1) {
							callback(res.data);
						} else if (res.data.code == 0) {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						} else if (res.data.code == 1001) {
							uni.reLaunch({
								url: "/pages/login/login"
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
					},
					fail: function(res) {
						console.log(res);
						console.error(url + '请求失败');
					},
					complete: function(res) {}
				});
			}
		}
	};
</script>

<style>
	/*每个页面公共css */
</style>